﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
using System.Diagnostics;
using System.Resources;
using System.Threading;
using System.Reflection;
using Screenshot2Disk.Localization;
using System.Drawing;

namespace Screenshot2Disk
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

#if DEBUG
            //args = new[] { @"F:\tests\" };
#endif

            if (args == null || args.Count() == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
            else
            {
                var path = args[0];

                if (Clipboard.ContainsImage())
                {
                    using(var img = Clipboard.GetImage())
                    {
                        ImageFormat imageFormat;
                        int compression;
                        Form1.GetImageSettings(out imageFormat, out compression);

                        ImageHelper.SaveImage(img, path, imageFormat, compression);
                    }
                }
                else
                    Msg.ShowError("There is no image or no supported image format in clipboard");

                //var formats = ClipboardFormat.GetSupportedFormats();
                //if (formats.Count() == 1)
                //{
                //    ClipboardHelper.Handle(path, formats.First());
                //}
                //else if (formats.Count() > 0)
                //{
                //    Application.EnableVisualStyles();
                //    Application.SetCompatibleTextRenderingDefault(false);

                //    Application.Run( new OutputForm(path, formats));
                //}
            }
        }
    }
}
